<?php

namespace App\Models\Posts;

use App\Wen\Utils\Settings;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;

class WxPostsVideo extends Model
{
	use HasDateTimeFormatter;
    use SoftDeletes;

    protected $fillable = ['posts_id', 'user_id', 'video_url', 'video_thumb_url', 'video_width', 'video_height', 'posts_video_state'];

    protected $appends = ['show_type', 'h_w_ratio', 'display_height'];

    protected $table = 'wx_posts_video';


    public function getShowTypeAttribute($key)
    {
        if ($this->video_height > $this->video_width){
            return 0;// 竖屏显示
        }else{
            return 1;// 横屏显示
        }

    }

    // 高宽比
    public function getHWRatioAttribute()
    {
        if(_empty_($this->video_width)){
            return 0.65;
        }
        return round($this->video_height / $this->video_width, 2);
    }

    public function getDisplayHeightAttribute()
    {
        $height = $this->h_w_ratio * 750;
        if($height > 690){
            return 690;
        }else{
            return $height;
        }
    }

    public function getVideoWidthAttribute($value){
        // 3审核中 4冻结中 5已清理
        if($this->posts_video_state == 3){
            return 710;
        }
        if($this->posts_video_state == 4){
            return 710;
        }
        if($this->posts_video_state == 5){
            return 710;
        }
        return $value;
    }

    public function getVideoHeightAttribute($value){
        // 3审核中 4冻结中 5已清理
        if($this->posts_video_state == 3){
            return 490;
        }
        if($this->posts_video_state == 4){
            return 490;
        }
        if($this->posts_video_state == 5){
            return 490;
        }
        return $value;
    }

    public function getVideoThumbUrlAttribute($value){
        // 3审核中 4冻结中 5已清理
        if($this->posts_video_state == 3){
            return env('APP_URL') . '/statics/video/cos/cos_review_1.jpg';
        }
        if($this->posts_video_state == 4){
            return env('APP_URL') . '/statics/video/cos/cos_review_2.jpg';
        }
        if($this->posts_video_state == 5){
            return env('APP_URL') . '/statics/video/cos/cos_review_3.jpg';
        }
        return $value;
    }



    public function getVideoUrlAttribute($value)
    {
        // 3审核中 4冻结中 5已清理
        if($this->posts_video_state == 3){
            return env('APP_URL') . '/statics/video/cos/cos_review_1.mp4';
        }
        if($this->posts_video_state == 4){
            return env('APP_URL') . '/statics/video/cos/cos_review_2.mp4';
        }
        if($this->posts_video_state == 5){
            return env('APP_URL') . '/statics/video/cos/cos_review_3.mp4';
        }
        return $value;
    }



}
